package com.realshare.frame.beetlsql.config;

import org.beetl.sql.core.DefaultNameConversion;
import org.beetl.sql.core.NameConversion;

import java.util.Map;

/**
 * ${DESCRIPTION}
 * author leisure
 * email 15075107120@139.com
 * create 2019-02-20 下午 6:08
 * modify 2019-02-20 下午 6:08
 **/
public class UnderlinedNameConversion extends org.beetl.sql.core.UnderlinedNameConversion {

    private NameConversion nc;

    public UnderlinedNameConversion() {
        nc = new DefaultNameConversion();
    }

    public String getColName(Class<?> c, String attrName) {
        if (c != null && Map.class.isAssignableFrom(c)) {
            return nc != null ? nc.getColName(attrName) : attrName;
        }
        return super.getColName(c, attrName);
    }

    public String getPropertyName(Class<?> c, String colName) {
        if (c != null && Map.class.isAssignableFrom(c)) {
            return nc != null ? nc.getPropertyName(c, colName) : colName;
        }
        return super.getPropertyName(c, colName);
    }

    public String getTableName(Class<?> c) {
        return super.getTableName(c);
    }
}
